package org.ricks.game.hotfix;

// 自定义类加载器（支持隔离加载）
public class ReloadableClassLoader extends ClassLoader {
    private final byte[] classBytes;
    private final String targetClassName;

    public ReloadableClassLoader(ClassLoader parent, byte[] classBytes, String className) {
        super(parent); // 显式设置父加载器保证基础类一致性
        this.classBytes = classBytes;
        this.targetClassName = className;
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        if (name.equals(targetClassName)) {
            return defineClass(name, classBytes, 0, classBytes.length);
        }
        return super.findClass(name); // 其他类委派父加载器
    }
}